package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleService;
import com.heima.common.constants.message.HotArticleConstants;
import com.heima.model.article.mess.ArticleVisitStreamMess;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * @作者 itcast
 * @创建日期 2021/4/26 15:18
 **/
@Component
@Slf4j
public class ArticleIncrHandleListener {

    @Autowired
    ApArticleService apArticleService;


    @KafkaListener(topics = HotArticleConstants.HOTARTICLE_INCR_HANDLE_OUPUT_TOPIC)
    public void hotArticleUpdateHandler(String message){
        log.info(" 接收到流处理后的消息 准备更新文章热度  ===> {} ",message);
        ArticleVisitStreamMess streamMess = JSON.parseObject(message, ArticleVisitStreamMess.class);
        apArticleService.updateApArticle(streamMess);
        log.info("更新文章热度执行完毕 ==================end  === ");
    }


}
